<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>JavaScript及jQuery中的各种宽高属性图解 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="JavaScript,">
  

  <meta name="description" content="原文链接 http://blog.poetries.top/2016/12/13/js-props声明：本文根据慕课网学习视频整理  强烈建议打开控制台自己动手练习一遍，这样印象才会深刻 第一部分 JavaScript中的宽高属性 一、与window相关的宽高属性 1.1 window.location和document.location  window对象的location属性引用的是loca">
<meta name="keywords" content="JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript及jQuery中的各种宽高属性图解">
<meta property="og:url" content="http://blog.poetries.top/2016/12/13/js-props/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="原文链接 http://blog.poetries.top/2016/12/13/js-props声明：本文根据慕课网学习视频整理  强烈建议打开控制台自己动手练习一遍，这样印象才会深刻 第一部分 JavaScript中的宽高属性 一、与window相关的宽高属性 1.1 window.location和document.location  window对象的location属性引用的是loca">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1480597-d7979b36ca991d9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1480597-7c90cc88a3355d8e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/322.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/323.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/324.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/325.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/326.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/327.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/328.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/329.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/330.png">
<meta property="og:image" content="https://camo.githubusercontent.com/3318530334bbc8f5e7ce267866c43ba72fa01f32/687474703a2f2f6f61376436647871742e626b742e636c6f7564646e2e636f6d2f626c6f672f696d616765732f3038313734323039323736363338392e6a7067">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/331.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/332.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/333.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/334.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/335.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/336.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/337.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/338.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/339.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/340.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/341.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/342.png">
<meta property="og:updated_time" content="2020-08-15T04:25:31.926Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript及jQuery中的各种宽高属性图解">
<meta name="twitter:description" content="原文链接 http://blog.poetries.top/2016/12/13/js-props声明：本文根据慕课网学习视频整理  强烈建议打开控制台自己动手练习一遍，这样印象才会深刻 第一部分 JavaScript中的宽高属性 一、与window相关的宽高属性 1.1 window.location和document.location  window对象的location属性引用的是loca">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/1480597-d7979b36ca991d9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#第一部分-JavaScript中的宽高属性"><span class="toc-text">第一部分 JavaScript中的宽高属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#一、与window相关的宽高属性"><span class="toc-text">一、与window相关的宽高属性</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-window-location和document-location"><span class="toc-text">1.1 window.location和document.location</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-2-window-screen"><span class="toc-text">1.2 window.screen</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#二、与document相关的宽高属性"><span class="toc-text">二、与document相关的宽高属性</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-1与client相关的宽高"><span class="toc-text">2.1与client相关的宽高</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-2-与offset相关的宽高"><span class="toc-text">2.2 与offset相关的宽高</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-3与scroll相关的宽高-实际项目中用的最多"><span class="toc-text">2.3与scroll相关的宽高 (实际项目中用的最多)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-documentElement和body的关系"><span class="toc-text">2.4 documentElement和body的关系</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三、Event对象的5种坐标"><span class="toc-text">三、Event对象的5种坐标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#四、-js各种宽高的应用"><span class="toc-text">四、 js各种宽高的应用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#五、js中的宽高属性总结"><span class="toc-text">五、js中的宽高属性总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第二部分-jQuery中的宽高属性"><span class="toc-text">第二部分 jQuery中的宽高属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#一、jquery相关宽高介绍"><span class="toc-text">一、jquery相关宽高介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#二、jquery相关宽高举例"><span class="toc-text">二、jquery相关宽高举例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三、jquery各种宽高应用"><span class="toc-text">三、jquery各种宽高应用</span></a></li></ol></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-js-props" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">JavaScript及jQuery中的各种宽高属性图解</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2016.12.13</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 4.3k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 18分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <blockquote>
<p>原文链接 <a href="http://blog.poetries.top/2016/12/13/js-props">http://blog.poetries.top/2016/12/13/js-props</a><br>声明：本文根据慕课网学习视频整理</p>
</blockquote>
<p>强烈建议打开控制台自己动手练习一遍，这样印象才会深刻</p>
<h2 id="第一部分-JavaScript中的宽高属性"><a href="#第一部分-JavaScript中的宽高属性" class="headerlink" title="第一部分 JavaScript中的宽高属性"></a>第一部分 JavaScript中的宽高属性</h2><hr>
<h3 id="一、与window相关的宽高属性"><a href="#一、与window相关的宽高属性" class="headerlink" title="一、与window相关的宽高属性"></a>一、与window相关的宽高属性</h3><hr>
<h4 id="1-1-window-location和document-location"><a href="#1-1-window-location和document-location" class="headerlink" title="1.1 window.location和document.location"></a>1.1 window.location和document.location</h4><hr>
<ul>
<li><code>window</code>对象的<code>location</code>属性引用的是<code>location</code>对象，表示该窗口中当前显示文档的<code>URL</code></li>
<li><code>document</code>的对象的<code>location</code>属性也是引用<code>location</code>对象</li>
<li>所以 <code>window.location === document.location</code>    <code>//true</code><a id="more"></a>
<h4 id="1-2-window-screen"><a href="#1-2-window-screen" class="headerlink" title="1.2 window.screen"></a>1.2 window.screen</h4></li>
</ul>
<hr>
<ul>
<li><code>window.screen</code>包含有关用户屏幕的信息。它包括：<ul>
<li><code>window.screen.width</code></li>
<li><code>window.screen.height</code></li>
<li><code>window.screen.availHeight</code></li>
<li><code>window.screen.availWidth</code></li>
<li><code>window.screenTop</code></li>
<li><code>window.screenLeft</code></li>
</ul>
</li>
</ul>
<p><img src="http://upload-images.jianshu.io/upload_images/1480597-d7979b36ca991d9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="window.screen"></p>
<p><strong>1.3 与window相关的宽高</strong></p>
<ul>
<li><code>window.innerWidth</code>   内部的宽度</li>
<li><code>window.innerHeight</code>   内部的高度</li>
<li><code>window.outWidth</code>   外部的宽度</li>
<li><code>window.outHeight</code>   外部的高度</li>
</ul>
<p><img src="http://upload-images.jianshu.io/upload_images/1480597-7c90cc88a3355d8e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="与window相关的宽高"></p>
<h3 id="二、与document相关的宽高属性"><a href="#二、与document相关的宽高属性" class="headerlink" title="二、与document相关的宽高属性"></a>二、与document相关的宽高属性</h3><hr>
<h4 id="2-1与client相关的宽高"><a href="#2-1与client相关的宽高" class="headerlink" title="2.1与client相关的宽高"></a>2.1与client相关的宽高</h4><hr>
<ul>
<li><code>document.body.clientWidth</code> 元素宽度（可视内容区+内边距）</li>
<li><code>document.body.clientHeight</code>元素高度（可视内容区+内边距）</li>
</ul>
<p>该属性指的是元素的可视部分宽度和高度，即<code>padding+content</code><br>如果没有滚动条，即为元素设定的宽度和高度<br>如果出现滚动条，滚动条会遮盖元素的宽高，那么该属性就是其本来宽高减去滚动条的宽高</p>
<p>example1：</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125; </span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.clientWidth);  <span class="comment">// 350+padding(80) = 430</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.clientHeight);  <span class="comment">// 500 + padding(80) = 580</span></span><br></pre></td></tr></table></figure>
<p>example2: 在div中添加文字， 指导出现滚动条</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">#exp2 &#123;</span><br><span class="line">	width:<span class="number">200</span>px;</span><br><span class="line">	height:<span class="number">200</span>px;</span><br><span class="line">	background:red;</span><br><span class="line">	border:1px solid #000;</span><br><span class="line">	overflow:auto;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> test = <span class="built_in">document</span>.getElementById(<span class="string">"exp2"</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>,log(test.clientHeight); <span class="comment">// 200</span></span><br><span class="line"><span class="built_in">console</span>.log(test.clientWidth); <span class="comment">//</span></span><br></pre></td></tr></table></figure>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/322.png" alt></p>
<ul>
<li><p><strong>小结clientWidth和clientHeight</strong></p>
<ul>
<li>无<code>padding</code>无滚动 ： <code>clientWidth</code> = 盒子的<code>width</code></li>
<li>有<code>padding</code>无滚动 ： <code>clientWidth</code> = 盒子的<code>width</code> + 盒子的<code>padding * 2</code></li>
<li>有<code>padding</code>有滚动 ： <code>clientWidth</code> = 盒子和<code>width</code> + 盒子的<code>padding * 2</code>- 滚动轴宽度</li>
</ul>
</li>
</ul>
<ul>
<li><code>document.body.clientLeft</code></li>
<li><code>document.body.clientTop</code></li>
</ul>
<p>这两个返回的是元素周围边框的厚度，如果不指定一个边框或者不定位该元素，它的值就是0</p>
<p>例：</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125; </span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.clientLeft);  <span class="comment">// 20</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.clientTop);  <span class="comment">// 20</span></span><br></pre></td></tr></table></figure>
<p><strong>小结clientLeft和clientTop</strong></p>
<ul>
<li>这一对属性是用来读取元素的<code>border</code>的宽度和高度的<ul>
<li><code>clientTop = border-top</code></li>
<li><code>clientLeft = border-left</code></li>
</ul>
</li>
</ul>
<h4 id="2-2-与offset相关的宽高"><a href="#2-2-与offset相关的宽高" class="headerlink" title="2.2 与offset相关的宽高"></a>2.2 与offset相关的宽高</h4><hr>
<ul>
<li><strong>document.body.offsetWidth（元素的border+padding+content的宽度）</strong></li>
<li><strong>document.body.offsetHeight（元素的border+padding+content的高度）</strong></li>
</ul>
<p>该属性和其内部的内容是否超出元素大小无关，只和本来设定的border以及width和height有关</p>
<p>例：</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125; </span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.offsetWidth);  <span class="comment">// 470 = padding*2 + 350 + border*2</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body.offsetHeight);  <span class="comment">// 620 = padding*2 + 500 + border*2</span></span><br></pre></td></tr></table></figure>
<p><strong>小结offsetWidth和offsetHeight</strong></p>
<ul>
<li>无<code>padding</code>无滚动无<code>border</code><ul>
<li>offsetWidth = clientWidth = 盒子的宽度</li>
</ul>
</li>
<li>有<code>padding</code>无滚动有<code>border</code><ul>
<li>offsetWidth = 盒子的宽度 + 盒子padding<em>2 + 盒子边框</em>2 = clientWidth + 边框宽度*2</li>
</ul>
</li>
<li>有<code>padding</code>有滚动，且滚动是显示的，有<code>border</code><ul>
<li>offsetWidth = 盒子宽度 + 盒子padding<em>2 + 盒子边框</em>2 = clientWidth + 滚动轴宽度 + 边框宽度*2</li>
</ul>
</li>
</ul>
<hr>
<ul>
<li><strong>document.offsetLeft </strong></li>
<li><strong>document.offsetTop </strong></li>
</ul>
<p>了解这两个属性我们必须先了解它，什么是<code>offsetParent</code></p>
<ul>
<li>如果当前元素的父级元素没有进行<code>CSS</code>定位（<code>position</code>为<code>absolute</code>或<code>relative</code>）,<code>offsetParent</code>为<code>body.</code></li>
<li>假如当前元素的父级元素中有<code>CSS</code>定位，<code>offsetParent</code>取最近的那个父级元素</li>
</ul>
<p><strong>offsetLeft的兼容性问题：</strong></p>
<ul>
<li><p>在<code>IE6/7</code>中</p>
<ul>
<li><code>offsetLeft</code> = offsetParent的padding-left + 当前元素的margin-left</li>
</ul>
</li>
<li><p>在<code>IE8/9/10</code>以及<code>chrome</code>中</p>
<ul>
<li><code>offsetLeft</code> = offsetParent的margin-left + offsetParent的border宽度 + offsetParent的padding-left + 当前元素的margin-left</li>
</ul>
</li>
<li><p>在<code>FireFox</code>中</p>
<ul>
<li><code>offsetLeft</code> = offsetParent的margin-left + 当前元素的margin-left + offsetParent的padding-left</li>
</ul>
</li>
</ul>
<p>例：</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125; </span><br><span class="line"></span><br><span class="line">#exp &#123;</span><br><span class="line">   width:<span class="number">400</span>px;</span><br><span class="line">   height:<span class="number">200</span>px;</span><br><span class="line">   padding:<span class="number">20</span>px;</span><br><span class="line">   margin:<span class="number">10</span>px;</span><br><span class="line">   background:red;</span><br><span class="line">   border:20px solid #000;</span><br><span class="line">   overflow:auto;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> div = <span class="built_in">document</span>.getElementById(<span class="string">"exp"</span>);</span><br></pre></td></tr></table></figure>
<ul>
<li><p>在IE8/9/10以及chrome中：</p>
<ul>
<li>div.offsetLeft  = 本身的margin10 + 父级元素的padding40 + margin10 + border20 = 80</li>
<li>div.offsetTop = 本身的margin10 + 父级元素的padding40 + margin10 + border20 = 80</li>
</ul>
</li>
<li><p>在FireFox：（相比chrome中少了border）</p>
<ul>
<li>div.offsetLeft  = 本身的margin10 + 父级元素的padding40 + margin10 = 60</li>
<li>div.offsetTop = 本身的margin10 + 父级元素的padding40 + margin10 = 60</li>
</ul>
</li>
<li><p>在IE6/7中：（相比在FireFox，不但少了border还少了父级元素的margin）</p>
<ul>
<li><code>div.offsetLeft</code>  = 本身的<code>margin10</code> + 父级元素的<code>padding40</code> = 50</li>
<li><code>div.offsetTop</code> = 本身的<code>margin10</code> + 父级元素的<code>padding40</code> = 50</li>
</ul>
</li>
</ul>
<h4 id="2-3与scroll相关的宽高-实际项目中用的最多"><a href="#2-3与scroll相关的宽高-实际项目中用的最多" class="headerlink" title="2.3与scroll相关的宽高 (实际项目中用的最多)"></a>2.3与scroll相关的宽高 (实际项目中用的最多)</h4><hr>
<ul>
<li><strong>document.body.scrollWidth</strong></li>
<li><strong>document.body.scrollHeight</strong></li>
</ul>
<p>document.body的scrollWidth和scrollHeight与div的scrollWidth和scrollHeight是有区别的</p>
<p>例：</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">document</span>.body.scrollHeight; <span class="comment">// </span></span><br><span class="line"><span class="built_in">document</span>.body.scrollWidth; <span class="comment">//</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>当给定宽高小于浏览器窗口的宽高</p>
<ul>
<li>scrollWidth = 通常是浏览器窗口的宽度</li>
<li>scrollHeight = 通常是浏览器窗口的高度</li>
</ul>
</li>
<li><p>当给定宽高大于浏览器窗口的宽高，且内容小于给定宽高的时候</p>
<ul>
<li>scrollWidth = 给定宽度 + 其所有的padding + margin + border</li>
<li>scrollHeight = 给定高度 + 其所有的padding + margin + border</li>
</ul>
</li>
<li><p>当给定宽高大于浏览器窗口宽高，且内容大于给定宽高</p>
<ul>
<li>scrollWidth = 内容宽度 + 其所有的padding + margin + border</li>
<li>scrollHeight = 内容高度 + 其所有的padding + margin + border</li>
</ul>
</li>
</ul>
<p><strong>在某div中的scrollWidth和scrollHeight</strong></p>
<ul>
<li>无滚动轴时：<ul>
<li>scrollWidth = clientWidth = 盒子宽度 + 盒子padding*2 </li>
</ul>
</li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/323.png" alt></p>
<ul>
<li>有滚动轴时：<ul>
<li>scrollWidth = 实际内容的宽度 + padding*2</li>
<li>scrollHeight = 实际内容的高度 + padding*2</li>
</ul>
</li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/324.png" alt></p>
<ul>
<li><strong>document.body.scrollLeft</strong></li>
<li><strong>document.body.scrollTop</strong></li>
</ul>
<p>与前面不同的是，这对属性是可读写的，指的是当元素其中的超出其宽高的时候，元素被卷起来的高度和宽度</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">#exp &#123;</span><br><span class="line">   width:<span class="number">400</span>px;</span><br><span class="line">   height:<span class="number">200</span>px;</span><br><span class="line">   padding:<span class="number">20</span>px;</span><br><span class="line">   margin:<span class="number">10</span>px;</span><br><span class="line">   background:red;</span><br><span class="line">   border:20px solid #000;</span><br><span class="line">   overflow-y:scroll;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> mydiv = <span class="built_in">document</span>.getElementById(<span class="string">"exp"</span>);</span><br><span class="line"></span><br><span class="line">mydiv.scrollTop ;  <span class="comment">//默认情况下是0 </span></span><br><span class="line">mydiv.scrollLeft ; <span class="comment">//默认情况下是0 </span></span><br><span class="line"></span><br><span class="line"><span class="comment">//可以改写它</span></span><br><span class="line"></span><br><span class="line">mydiv.scrollTop = <span class="number">20</span>;</span><br><span class="line"><span class="built_in">console</span>.log(mydiv.scrollTop)</span><br></pre></td></tr></table></figure>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/325.png" alt></p>
<p><strong>obj.style.width和obj.style.height</strong></p>
<p>对于一个<code>DOM</code>元素，它的<code>style</code>属性返回的是一个对象，这个对象的任意一个属性是可读写的，<code>style.width</code>等于<code>css</code>属性中的宽度。<code>style.height</code>等于<code>css</code>属性中的高度</p>
<h4 id="2-4-documentElement和body的关系"><a href="#2-4-documentElement和body的关系" class="headerlink" title="2.4 documentElement和body的关系"></a>2.4 documentElement和body的关系</h4><hr>
<p>是父子级的关系</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">body&#123; </span><br><span class="line">    border: 20px solid #000; </span><br><span class="line">    margin: <span class="number">10</span>px; </span><br><span class="line">    padding: <span class="number">40</span>px; </span><br><span class="line">    background: #eee; </span><br><span class="line">    height: <span class="number">350</span>px; </span><br><span class="line">    width: <span class="number">500</span>px; </span><br><span class="line">    overflow: scroll; </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#exp &#123;</span><br><span class="line">   width:<span class="number">400</span>px;</span><br><span class="line">   height:<span class="number">200</span>px;</span><br><span class="line">   padding:<span class="number">20</span>px;</span><br><span class="line">   margin:<span class="number">10</span>px;</span><br><span class="line">   background:red;</span><br><span class="line">   border:20px solid #000;</span><br><span class="line">   overflow-y:scroll;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>); <span class="comment">//document</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.documentElement); <span class="comment">//html</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">document</span>.body); <span class="comment">//body</span></span><br></pre></td></tr></table></figure>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/326.png" alt></p>
<ul>
<li>兼容问题推荐使用 获取浏览器窗口可视区域大小</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.body.clientWidth || <span class="built_in">document</span>.documentElement.clientWidth;</span><br><span class="line"><span class="built_in">document</span>.body.clientHeight || <span class="built_in">document</span>.documentElement.clientHeight;</span><br></pre></td></tr></table></figure>
<h3 id="三、Event对象的5种坐标"><a href="#三、Event对象的5种坐标" class="headerlink" title="三、Event对象的5种坐标"></a>三、Event对象的5种坐标</h3><hr>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/327.png" alt></p>
<p>例：</p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example"</span> </span></span><br><span class="line"><span class="tag"><span class="attr">style</span>=<span class="string">"width: 200px;height: 200px;background: red;margin: 100px auto;"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> example = <span class="built_in">document</span>.getElementById(<span class="string">"example"</span>);</span><br><span class="line">example.onclick = <span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"clientX "</span>+e.clientX + <span class="string">" : "</span> + <span class="string">" clientY "</span>+e.clientY);</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"screenX "</span>+e.screenX + <span class="string">" : "</span> + <span class="string">" screenY "</span>+e.screenY);</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"offsetX "</span>+e.offsetX + <span class="string">" : "</span> + <span class="string">" offsetY "</span>+e.offsetY);</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"pageX "</span>+e.pageX + <span class="string">" : "</span> + <span class="string">" pageY "</span>+e.pageY);</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="string">"x "</span>+e.x + <span class="string">" : "</span> + <span class="string">" y "</span>+e.y);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/328.png" alt></p>
<h3 id="四、-js各种宽高的应用"><a href="#四、-js各种宽高的应用" class="headerlink" title="四、 js各种宽高的应用"></a>四、 js各种宽高的应用</h3><hr>
<ul>
<li><strong>example1：可视区域加载</strong></li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/329.png" alt></p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example1"</span> &gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-id">#example1</span> &#123;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">350px</span>;</span><br><span class="line">			<span class="attribute">background</span>: red;</span><br><span class="line">			<span class="attribute">margin</span>: <span class="number">1000px</span> auto <span class="number">0</span> auto;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">@-webkit-keyframes</span> fadeInLeft&#123;</span><br><span class="line">			0%&#123;</span><br><span class="line">				<span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line">				<span class="attribute">transform</span>: <span class="built_in">translate3d</span>(-<span class="number">100%</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			100%&#123;</span><br><span class="line">				<span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line">				<span class="attribute">transform</span>: none;</span><br><span class="line">				</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">			<span class="selector-class">.fadeInLeft</span> &#123;</span><br><span class="line">				<span class="attribute">animation-name</span>: fadeInLeft;</span><br><span class="line">				<span class="attribute">animation-duration</span>: <span class="number">2s</span>;</span><br><span class="line">			&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">showDiv</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			<span class="keyword">var</span> example = <span class="built_in">document</span>.getElementById(<span class="string">"example"</span>);</span><br><span class="line">			<span class="keyword">var</span> clients = <span class="built_in">window</span>.innerHeight || <span class="built_in">document</span>.documentElement.clientHeight || <span class="built_in">document</span>.body.clientHeight;<span class="comment">//可视区域的高度</span></span><br><span class="line">			<span class="keyword">var</span> divTop = example.getBoundingClientRect().top;</span><br><span class="line">			<span class="keyword">if</span>(divTop &lt;= clients)&#123;</span><br><span class="line">				example.classList.add(<span class="string">"fadeInLeft"</span>);</span><br><span class="line">                              <span class="comment">//  这里可以通过setAttribute设置图片的src按需加载</span></span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">document</span>.title = clients+<span class="string">"---"</span>+divTop;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line"><span class="built_in">window</span>.onscroll = showDiv;</span><br></pre></td></tr></table></figure>
<p> <a href="http://codepen.io/poetries/pen/RoeJgG" target="_blank" rel="noopener">在线演示</a></p>
<ul>
<li><strong>example2：网页滚动到顶部或者底部</strong></li>
</ul>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example2"</span> &gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-id">#example2</span> &#123;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">350px</span>;</span><br><span class="line">			<span class="attribute">background</span>: red;</span><br><span class="line">			<span class="attribute">margin</span>: <span class="number">1000px</span> auto <span class="number">0</span> auto;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">scrollTopOrBottom</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			<span class="keyword">var</span> example2 = <span class="built_in">document</span>.getElementById(<span class="string">"example"</span>);</span><br><span class="line">			<span class="keyword">var</span> clients = <span class="built_in">window</span>.innerHeight || <span class="built_in">document</span>.documentElement.clientHeight || <span class="built_in">document</span>.body.clientHeight;<span class="comment">//可视区域的高度，兼容性写法</span></span><br><span class="line">			<span class="keyword">var</span> scrollTop = <span class="built_in">document</span>.body.scrollTop;</span><br><span class="line">			<span class="keyword">var</span> wholeHeight = <span class="built_in">document</span>.body.scrollHeight;</span><br><span class="line">			<span class="keyword">if</span>(clients + scrollTop &gt;= wholeHeight)&#123;</span><br><span class="line">				alert(<span class="string">"我已经到了底部!"</span>);</span><br><span class="line">                              <span class="comment">// 这里可以调用Ajax分页加载到页面中，实现多页加载功能</span></span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(scrollTop == <span class="number">0</span>)&#123;</span><br><span class="line">				alert(<span class="string">"我已经到了顶部了!"</span>);</span><br><span class="line">                      </span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">document</span>.title = (clients + scrollTop)+<span class="string">"---"</span>+wholeHeight+<span class="string">"--"</span>+scrollTop;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line"><span class="built_in">window</span>.onscroll = scrollTopOrBottom;</span><br></pre></td></tr></table></figure>
<p><a href="http://codepen.io/poetries/pen/WoayJy" target="_blank" rel="noopener">在线演示</a></p>
<ul>
<li><strong>example3：DIV滚动到底部加载</strong></li>
</ul>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example3"</span> &gt;</span></span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line">			DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载DIV滚动到底部加载</span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-id">#example3</span> &#123;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">400px</span>;</span><br><span class="line">			<span class="attribute">background</span>: red;</span><br><span class="line">			<span class="attribute">margin</span>: <span class="number">10px</span> auto;</span><br><span class="line">			<span class="attribute">padding</span>: <span class="number">10px</span>;</span><br><span class="line">			<span class="attribute">overflow-y</span>: scroll;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> div = <span class="built_in">document</span>.getElementById(<span class="string">"example3"</span>);</span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">divScroll</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			</span><br><span class="line">			<span class="keyword">var</span> wholeHeight = div.scrollHeight;<span class="comment">//滚动区域高度</span></span><br><span class="line">			<span class="keyword">var</span> divScrollTop = div.scrollTop;<span class="comment">//卷上去的那部分高度</span></span><br><span class="line">			<span class="keyword">var</span> divHeight = div.clientHeight; <span class="comment">//div的可视区域的高度</span></span><br><span class="line">			</span><br><span class="line">			</span><br><span class="line">			<span class="keyword">if</span>(divScrollTop + divHeight &gt;= wholeHeight)&#123;</span><br><span class="line">				alert(<span class="string">"我已经到了底部!"</span>);</span><br><span class="line">               <span class="comment">// 这里可以在div中通过滚动加载分页按需显示</span></span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(divScrollTop == <span class="number">0</span>)&#123;</span><br><span class="line">				alert(<span class="string">"我已经到了顶部了!"</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">document</span>.title = (divScrollTop + divHeight)+<span class="string">"---"</span>+wholeHeight+<span class="string">"--"</span>+divScrollTop;</span><br><span class="line">&#125;</span><br><span class="line">		</span><br><span class="line">div.onscroll = divScroll;</span><br></pre></td></tr></table></figure>
<p><a href="http://codepen.io/poetries/pen/vyVrvm" target="_blank" rel="noopener">在线演示</a></p>
<ul>
<li><strong>example4：计算滚动轴的宽度</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//获取滚动轴的宽度</span></span><br><span class="line">	<span class="function"><span class="keyword">function</span> <span class="title">getScrollBar</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="keyword">var</span> el = <span class="built_in">document</span>.createElement(<span class="string">"p"</span>);</span><br><span class="line">		<span class="keyword">var</span> styles = &#123;</span><br><span class="line">			width:<span class="string">"100px"</span>,</span><br><span class="line">			height:<span class="string">"100px"</span>,</span><br><span class="line">			overflowY:<span class="string">"scroll"</span></span><br><span class="line">		&#125;;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">var</span> prop <span class="keyword">in</span> styles)&#123;</span><br><span class="line">			el.style[prop] = styles[prop];<span class="comment">//把 styles上的属性全部遍历拷贝到el.style上</span></span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">document</span>.body.appendChild(el);</span><br><span class="line">		<span class="keyword">var</span> scrollBarWidth = el.offsetWidth - el.clientWidth;</span><br><span class="line">		el.remove();</span><br><span class="line">		<span class="keyword">return</span> scrollBarWidth;</span><br><span class="line">	&#125;</span><br><span class="line">	alert(getScrollBar());<span class="comment">//17</span></span><br></pre></td></tr></table></figure>
<p><a href="http://codepen.io/poetries/pen/RoeBbL" target="_blank" rel="noopener">在线演示</a></p>
<h3 id="五、js中的宽高属性总结"><a href="#五、js中的宽高属性总结" class="headerlink" title="五、js中的宽高属性总结"></a>五、js中的宽高属性总结</h3><p><img src="https://poetries1.gitee.io/img-repo/2019/10/330.png" alt></p>
<p><img src="https://camo.githubusercontent.com/3318530334bbc8f5e7ce267866c43ba72fa01f32/687474703a2f2f6f61376436647871742e626b742e636c6f7564646e2e636f6d2f626c6f672f696d616765732f3038313734323039323736363338392e6a7067" alt></p>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/331.png" alt><br><img src="https://poetries1.gitee.io/img-repo/2019/10/332.png" alt></p>
<h2 id="第二部分-jQuery中的宽高属性"><a href="#第二部分-jQuery中的宽高属性" class="headerlink" title="第二部分 jQuery中的宽高属性"></a>第二部分 jQuery中的宽高属性</h2><hr>
<h3 id="一、jquery相关宽高介绍"><a href="#一、jquery相关宽高介绍" class="headerlink" title="一、jquery相关宽高介绍"></a>一、jquery相关宽高介绍</h3><hr>
<ul>
<li><strong>1.1 width()</strong><ul>
<li>特殊元素<code>window.document</code>只可以读，普通元素可以读写，<code>width()</code>返回结果无单位，<code>css(&quot;width&quot;)</code>的结果有单位</li>
</ul>
</li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/333.png" alt><br><img src="https://poetries1.gitee.io/img-repo/2019/10/334.png" alt></p>
<ul>
<li><strong>1.2 innerWidth()</strong><ul>
<li>包含padding（不推荐window,document调用）</li>
</ul>
</li>
<li><strong>1.3 innerHeight()</strong></li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/335.png" alt><br><img src="https://poetries1.gitee.io/img-repo/2019/10/336.png" alt></p>
<ul>
<li><strong>1.4 outerWidth()</strong><ul>
<li>包含padding和border，当传true时包含marging，不传时不包含marging（不推荐window,document调用）</li>
</ul>
</li>
<li><strong>1.5 outerHeight()</strong></li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/337.png" alt><br><img src="https://poetries1.gitee.io/img-repo/2019/10/338.png" alt></p>
<ul>
<li><strong>1.6 scrollLeft():</strong><ul>
<li>相对于水平滚动条左边的距离，如果滚动条非常左、或者元素不能被滚动，这个值为0；</li>
</ul>
</li>
<li><p><strong>1.7 scrollTop():</strong></p>
<ul>
<li>相对于垂直滚动条上边的距离，如果滚动条非常上、或者元素不能被滚动，这个值为0；</li>
</ul>
</li>
<li><p><strong>1.8 .offset():</strong></p>
<ul>
<li>相对于document的当前坐标值(相对于body左上角的left,top的值)；</li>
</ul>
</li>
<li><strong>1.9 .position():</strong><ul>
<li>相对于offset parent的当前坐标值(相对于offset parent元素的左上角的left、top的值)</li>
</ul>
</li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/339.png" alt></p>
<h3 id="二、jquery相关宽高举例"><a href="#二、jquery相关宽高举例" class="headerlink" title="二、jquery相关宽高举例"></a>二、jquery相关宽高举例</h3><hr>
<p><strong>2.1 exmaple1</strong></p>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/340.png" alt></p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"parentDiv"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"childrenDiv"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-tag">html</span>,<span class="selector-tag">body</span> &#123;</span><br><span class="line">	<span class="attribute">margin</span>:<span class="number">10px</span>;</span><br><span class="line">	<span class="attribute">border</span>:<span class="number">5px</span> solid red;</span><br><span class="line">	<span class="attribute">padding</span>:<span class="number">20px</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.parentDiv</span> &#123;</span><br><span class="line">	<span class="attribute">width</span>:<span class="number">800px</span>;</span><br><span class="line">	<span class="attribute">height</span>:<span class="number">500px</span>;</span><br><span class="line">	<span class="attribute">margin</span>:<span class="number">5px</span> auto;</span><br><span class="line">	<span class="attribute">background</span>:<span class="number">#FF6600</span>;</span><br><span class="line">	<span class="attribute">border</span>:<span class="number">5px</span> dashed green;<span class="attribute">padding</span>:<span class="number">30px</span>;<span class="attribute">position</span>:relative;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.childrenDiv</span> &#123;</span><br><span class="line">	<span class="attribute">width</span>:<span class="number">300px</span>;</span><br><span class="line">	<span class="attribute">height</span>:<span class="number">500px</span>;</span><br><span class="line">	<span class="attribute">margin</span>:<span class="number">5px</span> auto;</span><br><span class="line">	<span class="attribute">background</span>:yellow;</span><br><span class="line">	<span class="attribute">border</span>:<span class="number">5px</span> solid black;</span><br><span class="line">	<span class="attribute">padding</span>:<span class="number">5px</span>;</span><br><span class="line">	<span class="attribute">box-sizing</span>:border-box;<span class="comment">/*包括padding和border的值*/</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//特殊元素的高度</span></span><br><span class="line"><span class="comment">//window  document</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"$(window).height()"</span>+$(<span class="built_in">window</span>).height());</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"$(document).height()"</span>+$(<span class="built_in">document</span>).height());</span><br><span class="line"></span><br><span class="line"><span class="comment">//innerHeight </span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"$(window).innerHeight()"</span>+$(<span class="built_in">window</span>).innerHeight());</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"$(document).innerHeight()"</span>+$(<span class="built_in">document</span>).innerHeight());</span><br><span class="line"></span><br><span class="line"><span class="comment">//普通child元素的高度</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//480 = 500 - border*2 - padding*2 (因为设置了box-sizing，box-sizing把border和padding的值计算了进去)</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").height()'</span>+ $(<span class="string">".childrenDiv"</span>).height());</span><br><span class="line"></span><br><span class="line"><span class="comment">//490 = 500 - border*2 - padding*2（innerHeight不包括padding）</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").innerHeight()'</span>+ $(<span class="string">".childrenDiv"</span>).innerHeight());</span><br><span class="line"></span><br><span class="line"><span class="comment">//500 = 500  不包括margin</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").outerHeight()'</span>+ $(<span class="string">".childrenDiv"</span>).outerHeight());</span><br><span class="line"></span><br><span class="line"><span class="comment">//510 = 500 + margin true包括margin</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").outerHeight()'</span>+ $(<span class="string">".childrenDiv"</span>).outerHeight(<span class="literal">true</span>));</span><br><span class="line"></span><br><span class="line"><span class="comment">//scrollTop</span></span><br><span class="line"></span><br><span class="line">$(<span class="built_in">window</span>).scroll(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="built_in">document</span>.title = <span class="string">"scrollTop  "</span>+$(<span class="keyword">this</span>).scrollTop();</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// jquery宽高演示之offset和position</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").offset().top '</span>+$(<span class="string">".childrenDiv"</span>).offset().top);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").offset().left '</span>+$(<span class="string">".childrenDiv"</span>).offset().left);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").position().top '</span>+$(<span class="string">".childrenDiv"</span>).position().top);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'$(".childrenDiv").position().top '</span>+$(<span class="string">".childrenDiv"</span>).position().left);</span><br></pre></td></tr></table></figure>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/341.png" alt><br><img src="https://poetries1.gitee.io/img-repo/2019/10/342.png" alt></p>
<p><a href="http://codepen.io/poetries/pen/yVRqZO" target="_blank" rel="noopener">在线演示</a></p>
<h3 id="三、jquery各种宽高应用"><a href="#三、jquery各种宽高应用" class="headerlink" title="三、jquery各种宽高应用"></a>三、jquery各种宽高应用</h3><hr>
<p><strong>3.1 jquery可视区域加载</strong></p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example"</span> &gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-id">#example</span> &#123;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">350px</span>;</span><br><span class="line">			<span class="attribute">background</span>: red;</span><br><span class="line">			<span class="attribute">margin</span>: <span class="number">1000px</span> auto <span class="number">0</span> auto;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">@-webkit-keyframes</span> fadeInLeft&#123;</span><br><span class="line">			0%&#123;</span><br><span class="line">				<span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line">				<span class="attribute">transform</span>: <span class="built_in">translate3d</span>(-<span class="number">100%</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			100%&#123;</span><br><span class="line">				<span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line">				<span class="attribute">transform</span>: none;</span><br><span class="line">				</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">			<span class="selector-class">.fadeInLeft</span> &#123;</span><br><span class="line">				<span class="attribute">animation-name</span>: fadeInLeft;</span><br><span class="line">				<span class="attribute">animation-duration</span>: <span class="number">2s</span>;</span><br><span class="line">			&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">$(<span class="built_in">window</span>).scroll(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">var</span> ks_area = $(<span class="built_in">window</span>).height();<span class="comment">//可视区域高度</span></span><br><span class="line">	<span class="keyword">var</span> scrollHeight = $(<span class="built_in">window</span>).scrollTop();<span class="comment">//被卷上去的那部分</span></span><br><span class="line">	<span class="keyword">var</span> divTop = $(<span class="string">"#example"</span>).offset().top;<span class="comment">//盒子距离浏览器顶部的距离</span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span>(ks_area + scrollHeight &gt;= divTop)&#123;</span><br><span class="line">		$(<span class="string">"#example"</span>).addClass(<span class="string">"fadeInLeft"</span>);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">document</span>.title = ks_area+<span class="string">'-'</span>+scrollHeight+<span class="string">'-'</span>+divTop;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p><a href="http://codepen.io/poetries/pen/MbPqVE" target="_blank" rel="noopener">在线演示</a></p>
<p><strong>3.2 jquery滚动到底部和顶部加载</strong></p>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example"</span> &gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-id">#example</span> &#123;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">500px</span>;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">350px</span>;</span><br><span class="line">			<span class="attribute">background</span>: red;</span><br><span class="line">			<span class="attribute">margin</span>: <span class="number">1000px</span> auto <span class="number">0</span> auto;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">$(<span class="built_in">window</span>).scroll(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">var</span> ks_area = $(<span class="built_in">window</span>).height();</span><br><span class="line">	<span class="keyword">var</span> scrollTop = $(<span class="built_in">window</span>).scrollTop();</span><br><span class="line">	<span class="keyword">var</span> wholeHeight = $(<span class="built_in">document</span>).height();</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span>(ks_area + scrollTop &gt;=wholeHeight )&#123;</span><br><span class="line">		alert(<span class="string">"已经到底部了"</span>);</span><br><span class="line">	&#125;<span class="keyword">else</span> <span class="keyword">if</span>(scrollTop == <span class="number">0</span>)&#123;</span><br><span class="line">		alert(<span class="string">"已经到头部了"</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p><a href="http://codepen.io/poetries/pen/gLBdZa" target="_blank" rel="noopener">在线演示</a></p>
<p>（完）</p>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2016/12/13/arguments详解/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2016/12/30/video-audio/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
